/**
 * Created by Freeman on 2018/1/20.
 */
import uuid from 'uuid/v4'
import {LOG_IN_SUCCESS, LOG_OUT_SUCCESS, USER_INFO_SUCCESS} from '../../constants/ActionTypes'

const initAuth = {
  isLogged: false,
  userInfo: {},
  token: '',
  xUSSid: uuid()
}


export default function (state = initAuth, action) {
  switch (action.type) {
    case LOG_IN_SUCCESS :
      return {
        ...state,
        token: action.token,
        userInfo: action.userInfo,
        isLogged: action.isLogged,
      }
    case USER_INFO_SUCCESS :
      return {
        ...state,
        userInfo: action.userInfo,
      }
    case LOG_OUT_SUCCESS :
      return {
        ...state,
        token: null,
        userInfo: {},
        isLogged: false,
      }
    default :
      return state
  }
}
